<?php
class mproductcontent extends CI_Model{
	var $product = "product_content";

	function __construct()
	{
		parent::__construct();
	}
	
	function setData($id_product,$id_submenu,$title_product,$cost_product,$date_product,$file_product,$text_product,$enable_product)
	{
		$this->id_product= $id_product;
		$this->id_submenu= $id_submenu;
		$this->title_product= $title_product;
		$this->cost_product= $cost_product;
		$this->date_product= $date_product;
		$this->file_product= $file_product;
		$this->text_product= $text_product;
		$this->enable_product= $enable_product;
	}
	
	function getList($page,$uri_segment){
		$query = $this->db->get($this->product, $page, $uri_segment);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getComboList(){
		$query = $this->db->get($this->product);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function create()
	{	
		$arrayData = array(
			'id_product'=>$this->id_product,
			'id_submenu'=>$this->id_submenu,
			'title_product'=>$this->title_product,
			'cost_product'=>$this->cost_product,
			'date_product'=>$this->date_product,
			'file_product'=>$this->file_product,
			'text_product'=>$this->text_product,
			'enable_product'=>$this->enable_product
		);
		return $this->db->insert($this->product, $arrayData);
	}
	
	function update($id_product)
	{
		$arrayData = array(
			'id_submenu'=>$this->id_submenu,
			'title_product'=>$this->title_product,
			'cost_product'=>$this->cost_product,
			'date_product'=>$this->date_product,
			'file_product'=>$this->file_product,
			'text_product'=>$this->text_product,
			'enable_product'=>$this->enable_product
		);
		$this->db->where('id_product', $id_product);
		return $this->db->update($this->product, $arrayData);
	}
        
	function remove($id_product)
	{
		$this->db->where('id_product', $id_product);
		return $this->db->delete($this->product);
	}	
	
	function detail($id_product)
	{
		$this->db->where('id_product', $id_product);
		$query = $this->db->get($this->product);	
		return $query->result_array();
	}
	
	function getListSearch($name){
		$this->db->like('title_product',$name);
		$query = $this->db->get($this->product);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getDetForWeb($id_submenu){
		$this->db->where('id_submenu', $id_submenu);
		$query = $this->db->get($this->product);
		return $query->result_array();
	}
	
	function getForWebById($id_product){
		$this->db->where('id_product', $id_product);
		$query = $this->db->get($this->product);
		return $query->result_array();
	}
}
?>